package lesson02;

import javax.swing.*;
import java.awt.*;

public class IconDemp extends JFrame implements Icon {
    private int width, height;

    public IconDemp() {
    }

    public IconDemp(int width, int height) {
        this.width = width;
        this.height = height;
    }

    public static void main(String[] args) {
        new IconDemp().init();
    }

    public void init(){
        IconDemp icon = new IconDemp(15,15);
        //图标可以放在标签，也可以放在按钮上
        JLabel label = new JLabel("icontest",icon,SwingConstants.CENTER);
        Container container=getContentPane();
        container.add(label);
        this.setVisible(true);
    }
    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
        g.fillOval(x,y,width,height);
    }

    @Override
    public int getIconWidth() {
        return this.width;
    }

    @Override
    public int getIconHeight() {
        return this.height;
    }
}
